package com.taplinker.client.crm.rpc;


import android.widget.Toast;

import com.taplinker.client.AppConfigContext;
import com.taplinker.client.crm.domain.CrmDataCenter;
import com.taplinker.client.crm.domain.CustomerInfo;
import com.taplinker.core.rpc.Result;
import com.taplinker.core.rpc.command.SimpleBaseCommand;
import com.taplinker.core.rpc.http.HttpTemplate;
import com.taplinker.dto.web.AssignCustomerProto;
import com.taplinker.dto.web.AssignCustomerProto.AssignCustomer.Builder;
/**
 * 指定客户
 * @author djbian
 *
 */
public class AssignCustomer extends SimpleBaseCommand {

	private static final String TAG = "AssignCustomer";
	private CustomerInfo info;
	private String reason;
	private String userId;
	public AssignCustomer(CustomerInfo info,String reason,String userId)
	{
		this.info = info;
		this.reason = reason;
		this.userId = userId;
	}
	
	@Override
	public Result go() {
		Builder b = AssignCustomerProto.AssignCustomer.newBuilder();
		b.setReason(reason);
		b.setTo(userId);
		b.setCustomerId(info.getCustomer().getId());
		return new HttpTemplate().postForGogoByte(AppConfigContext.TAPLINKER_WEB
				+ "/services/crm/v1/customer/assign/"+info.getCustomer().getVistorId()
				, b.build().toByteArray());
	}
	
	@Override
	public void yes(Result result) {
		super.yes(result);
		CrmDataCenter.getInstance().noticeListener(CrmDataCenter.ASSIGN_CUSTOMER);
	}

	@Override
	public void no(Result result) {
		Toast.makeText(CrmDataCenter.getInstance().getContext(), "" + result.message, Toast.LENGTH_SHORT).show();
	}
}
